#!/bin/bash
fileName="/app/city_app/opt/monitor"
buzzGPIO="/sys/class/gpio/gpio15"
#enable buzzse for notifying success
function beep_notify()
{
   if [ ! -d "$buzzGPIO" ]; then
        echo 15 > /sys/class/gpio/export
   fi

   if [ -d "$buzzGPIO" ]; then
        echo "out" > "/sys/class/gpio/gpio15/direction"
        echo "1" > "/sys/class/gpio/gpio15/value"
        sleep 1
        echo "0" > "/sys/class/gpio/gpio15/value"
   fi
}

function CheckProcess()
{
  PROCESS_NUM=`ps | grep "$1" | grep -v "grep" | wc -l`
  
  return $PROCESS_NUM
}
if [ ! -f $fileName ]; then  
　　    echo "error!monitor file not exit!"
        exit 1
    else 
	echo "find monitor file,begin start..."
		CheckProcess qrlinux
		if [ $? -eq 0 ];then
		echo "no monitor progress find!"
		else
		echo "find monitor,..."
	    killall -9 monitor
        sleep 1
        fi 
        cd /app/city_app/opt/
	    ./monitor  & 	
	    echo "start ok"
	    beep_notify
	    exit 0
fi
